package com.google.code.roadmap.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.google.code.roadmap.dao.RoadMapDao;
import com.google.code.roadmap.service.RoadMapService;
import com.google.code.roadmap.web.domain.RoadMap;

@Service("roadMapService")
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public class RoadMapServiceImpl implements RoadMapService {

	/**
	 * 사용자 JDBC DAO DI
	 */
	@Resource(name = "roadMapJdbcDao")
	private RoadMapDao roadMapDao;

	@Override
	public RoadMap getRoadMap(Integer idNum) {

		RoadMap roadMap = roadMapDao.getRoadMap(idNum);

		Integer north = roadMap.getNorth().getIdNum();
		Integer south = roadMap.getSouth().getIdNum();
		Integer east = roadMap.getEast().getIdNum();
		Integer west = roadMap.getWest().getIdNum();
		Integer ne = roadMap.getNe().getIdNum();
		Integer nw = roadMap.getNw().getIdNum();
		Integer se = roadMap.getSe().getIdNum();
		Integer sw = roadMap.getSw().getIdNum();

		if (north != null && north != 0) {
			roadMap.setNorth(roadMapDao.getRoadMap(north));
		}
		if (south != null && south != 0) {
			roadMap.setSouth(roadMapDao.getRoadMap(south));
		}
		if (east != null && east != 0) {
			roadMap.setEast(roadMapDao.getRoadMap(east));
		}
		if (west != null && west != 0) {
			roadMap.setWest(roadMapDao.getRoadMap(west));
		}

		if (ne != null && ne != 0) {
			roadMap.setNe(roadMapDao.getRoadMap(ne));
		}
		if (nw != null && nw != 0) {
			roadMap.setNw(roadMapDao.getRoadMap(nw));
		}
		if (se != null && se != 0) {
			roadMap.setSe(roadMapDao.getRoadMap(se));
		}
		if (sw != null && sw != 0) {
			roadMap.setSe(roadMapDao.getRoadMap(sw));
		}

		return roadMap;
	}

}
